count = 0
n = input()
if 999 < int(n) < 10000 :
    for left in range(4):
        for right in range(left+1, 4):
            num = int(n[left:right+1])
            c = 0
            for d in range(2, num // 2):
                if num % d == 0:
                    c = 1
            if c != 1 and num > count:
                count = num
print(count)